|
|
|
|
|
|
|
Show method and a PrintForm method. The Employee form is displayed differently and printed differently from the TimeSheet form, but each one has the same method names. |
|
|
|
|
|
|
|
|
In a procedural language, you would have to come up with different names for each of the functions to show or print a screen, such as EmpShow, EmpPrint, TimeSheetShow, and TimeSheetPrint. For us as programmers, this makes it more difficult to remember all these function names. It also makes it more difficult to keep coming up with new names that are unique for each new form added to the application. |
|
|
|
|
|
|
|
|
Its very important to stay consistent in the naming of your methods. If youve defined one verb (Show) as the method used to display an object, all your objects should always use the same verb. If you teach all your programmers to use this one verb, they only need to memorize one word. |
|
|
|
|
|
|
|
|
As we all know, different people can use different verbs to describe the same action. One programmer may create an object and call the method to display this object Show. Another programmer may create another object and call the method to display this object Display. Yet another creates another object and calls the method to display the object Draw. All three verbs mean the same thing, but each object now has a completely different interface. For new programmers trying to use these objects, they now have to look up the method used to display a particular object. |
|
|
|
|
|
|
|
|
Another advantage to this consistency is that you can create a collection of objects in an application that you need to iterate over and invoke a method. If the method to invoke has the same name across all objects, you only need one line of code to accomplish this. Heres an example: |
|
|
|
 |
|
|
|
|
Dim oObject As Object
For Each oObject In colOfObjects
oObject.Show
Next |
|
|
|
|
|
|
|
|
If the objects didnt have a consistent interface, the following code would have to be written: |
|
|
|
 |
|
|
|
|
Dim oObject As Object
For Each oObject In colOfObjects
If TypeOf oObject is Employee |
|
|
|
|
|